﻿
function init() {

    if ($.getPara('dicttypeid') != '') {
        initexttype();
    }
    $('#save').bind('click', function () { save(); });
}

//上传
function doUpload(idstr, namestr, attType, formid) {
    var file = $('#upload' + idstr).val();
    if ($.trim(file) == '') {
        alert(lang.select_need_to_upload + namestr);
        return false;
    }
    var ext = file.substr(file.lastIndexOf('.') + 1);
    var extReg = /^(jpg|gif|png)$/;
    if (!extReg.test(ext)) {
        alert(lang.the_following_types_only_support + '：jpg、gif、png');
        return false;
    }
    var options = {
        type: "post",
        dataType: 'json',
        url: App_Config.TadongUrl + '/Upload.aspx?fileType=prePic',
        success: function (data) {
            if (data.status == 0) {
                if (file.lastIndexOf('\\') > 0) {
                    file = file.substr(file.lastIndexOf('\\') + 1); //chrome会变成c;/fakepath/xxx.jpg
                }
                var _url = downloadurl('feedback', data.fileName, data.realName);
                $('#attachinfo').html('<span><input id="attach_name" type="hidden" value="' + data.realName + '"/><input id="attach_url" type="hidden" value="' + data.fileName + '"/><a href = "' + _url + '">' + data.realName + '</a><span onclick="deleteattach();" style="cursor:pointer;padding-left:15px;color:blue;">' + lang.delete_ + '</span></span>');
            }
            else {
                alert(lang.upload_failure);
            }
        }
    };
    $('#' + formid).ajaxSubmit(options);
}

function deleteattach() {
    $('#attachinfo').html('');
}


//保存
function save() {

    $.ajaxHandler({
        url: App_Config.TadongUrl + "/AjaxMappingHandler.aspx",
        urlType: "PrePicAdd",
        model: function () {
            var obj = {};
            obj.FILE_ID = $.getPara('fileid');
            obj.SPACE = $.getPara('space');
            if ($('#attach_url').val() != '') {
                obj.PRE_PIC = $('#attach_url').val();
            }
            return $.toJSON(obj);
        },
        success: function (data) {
            if (data) {
                alert(lang.add_new_element_success);

            }
        }
    });
}

function exit() {
    parent.$.closePage();
}